﻿namespace Blaze.Framework.MonoEventListeners
{
    using UnityEngine;

    public class Lifecycle : MonoBehaviour
    {
        public event EventHandler FixedUpdateEvent;

        public event EventHandler LateUpdateEvent;

        public event EventHandler OnDestroyEvent;

        public event EventHandler OnDisableEvent;

        public event EventHandler OnEnableEvent;

        public event EventHandler StartEvent;

        public event EventHandler UpdateEvent;

        public static Lifecycle Get(GameObject obj)
        {
            return obj.GetOrAddComponent<Lifecycle>();
        }

        private void FixedUpdate()
        {
            if (FixedUpdateEvent != null)
                FixedUpdateEvent(gameObject);
        }

        private void LateUpdate()
        {
            if (LateUpdateEvent != null)
                LateUpdateEvent(gameObject);
        }

        private void OnDestroy()
        {
            if (OnDestroyEvent != null)
                OnDestroyEvent(gameObject);
        }

        private void OnDisable()
        {
            if (OnDisableEvent != null)
                OnDisableEvent(gameObject);
        }

        private void OnEnable()
        {
            if (OnEnableEvent != null)
                OnEnableEvent(gameObject);
        }

        private void Start()
        {
            if (StartEvent != null)
                StartEvent(gameObject);
        }

        private void Update()
        {
            if (UpdateEvent != null)
                UpdateEvent(gameObject);
        }
    }
}